/**
 * 
 */
package cs342.project1.mathNotebook.gui;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.table.AbstractTableModel;

import cs342.project1.mathNotebook.db.DBNotebook;
import cs342.project1.mathNotebook.db.DatabaseContext;
import cs342.project1.mathNotebook.db.DatabaseException;

/**
 * @author aaron
 *
 */
public class OpenNotebookTableModel extends AbstractTableModel {
	protected DBNotebook[] notebooks;
	/**
	 * @throws DatabaseException
	 * 
	 */
	public OpenNotebookTableModel(DBNotebook[] notebooks) {
		//get notebooks
		this.notebooks = notebooks;
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	@Override
	public int getColumnCount() {
		return 3;
	}
	
	@Override
	public String getColumnName(int col) {
		switch(col) {
		case 0:
			return "Owner Username";
		case 1:
			return "Notebook ID";
		case 2:
			return "Last Modified";
		}
		return "";
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	@Override
	public int getRowCount() {
		return notebooks.length;
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	@Override
	public Object getValueAt(int row, int col) {
		DBNotebook notebookForRow = notebooks[row];
		switch(col) {
		case 0:
			try {
				return notebookForRow.getOwner().getUsername();
			} catch (DatabaseException e) {
				return null;
			}
		case 1:
			return notebookForRow.getId();
		case 2:
			try {
				return notebookForRow.getLastUpdatedDate();
			} catch (DatabaseException e) {
				return null;
			}
		}
		return null;
	}
	
	@Override
	public boolean isCellEditable(int row, int col) {
		return false;
	}

}
